var gl_vue_vm_list_elderOutCost_html = $('#vue_vm_list_elderOutCost').html();

var elderBeHospital = null;
var beHospitalId = null;

$(function() {
	$('#vue_vm_list div').hide();
	$('#vue_vm_list_elderOutCost div').hide();
	$('#houseTypeType_vipCard').hide();
	$('#houseTypeType_ordinary').hide();
	
	var elderBeHospitalId = $.url().param('elderBeHospitalId');
	var searchVal = $.url().param('searchVal');
	if(searchVal) {
		$('#searchVal').val(searchVal);
	}
	
	if(elderBeHospitalId) {
		find_elder_by_elderBeHospitalId(elderBeHospitalId);
	}
});

var beHospitalFees = {
	beHospitalFeesId: '',
	elderId: '',
	isFinancialCs: '',
	bankName: '',
	contactName: '',
	contactPhoneNumer: '',
	beHospitalTime: '',
	outHospitalTime: '',
	subsidyApply: '',
	pledgePay: '',
	mealCardPay: '',
	elderWalletPay: '',
	electricityPay: '',
	waterPay: '',
	hotWaterPay: '',
	totalPay: '',
	realityPay: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	createName: getLoginedUser()? getLoginedUser().staffName: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	updateName: getLoginedUser()? getLoginedUser().staffName: '',
	bedCost: '',
	nursingCost: '',
	baseServiceCost: '',
    beHospitalId:''
};

var view = {
	data: beHospitalFees
};

if($('#vue_vm').length > 0) {
	var vue_vm = new Vue({
		el: '#vue_vm',
		data: view
	});
}

function save() {
	feesInputChange(); //为了防止事件的响应不及时，在提交之前必须运行一次事件处理代码。
	
	if(view.data.elderId=='') {
		alert('请先查询长者');
		return;
	}
	
	if($('#isFinancialCs').is(':checked')) {
		view.data.isFinancialCs = 1;
		view.data.bankName = $('#bankName').val();
		view.data.contactName = $('#contactName').val();
		view.data.contactPhoneNumer = $('#contactPhoneNumer').val();
	}else {
		view.data.isFinancialCs = 2;
		view.data.bankName = null;
		view.data.contactName = null;
		view.data.contactPhoneNumer = null;
	}
	
	// view.data.beHospitalTime = $('#beHospitalYear').val() + '-' + $('#beHospitalMonth').val() + '-' + $('#beHospitalDay').val();
	//view.data.outHospitalTime = $('#outHospitalYear').val() + '-' + $('#outHospitalMonth').val() + '-' + $('#outHospitalDay').val();
	// var option = $('#foodAllowance_select option:selected');
	// view.data.allowanceName = option.text();
	view.data.subsidyApply = view.data.allowanceName;
	
	view.data.pledgePay = (view.data.pledgePay==''? 0: parseFloat(view.data.pledgePay));
	view.data.mealCardPay = (view.data.mealCardPay==''? 0: parseFloat(view.data.mealCardPay));
	view.data.elderWalletPay = (view.data.elderWalletPay==''? 0: parseFloat(view.data.elderWalletPay));
	view.data.electricityPay = (view.data.electricityPay==''? 0: parseFloat(view.data.electricityPay));
	view.data.waterPay = (view.data.waterPay==''? 0: parseFloat(view.data.waterPay));
	view.data.hotWaterPay = (view.data.hotWaterPay==''? 0: parseFloat(view.data.hotWaterPay));
	view.data.totalPay = (view.data.totalPay==''? 0: parseFloat(view.data.totalPay));
	view.data.realityPay = (view.data.realityPay==''? 0: parseFloat(view.data.realityPay));
	view.data.bedCost = view.data.bedCostForHalfMoon;
	view.data.nursingCost = view.data.nursingCostForHalfMoon;
	view.data.baseServiceCost = view.data.baseServiceCostForHalfMoon;

	save_basic(path+'/beHospitalFees/save', {beHospitalFees:view.data}, function(response) {
		alert('入院缴费成功');
		view.data.createTime = response.data[0].createTime;
		window.location.href = '3-3-1ryjiaofei-1.html?elderBeHospitalId='+view.data.elderBeHospitalId+'&pageParam='+encodeURIComponent(JSON.stringify(view.data));
		//window.open('3-3-1ryjiaofei-1.html?elderBeHospitalId='+view.data.elderBeHospitalId+'&pageParam='+encodeURIComponent(JSON.stringify(view.data)));
	});
}

findElderInfoByElderId = function(elderId) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	$('#vue_vm_list').hide();
	
	find_basic_by_json(path+'/beHospitalFees/findElderInfoByElderId', {elderId: elderId}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		if(response.data.length > 0) {
			var pledgePay = response.data[0].beHospitalFeeForm==null? 0: response.data[0].beHospitalFeeForm.pledgePay;
			$('#pledgePay').text(pledgePay+'元');
			$('#pledgePay_input').val(pledgePay);
		}
		
		if(response.data[0].elderBeHospitalForm!=null) {
			if(response.data[0].elderBeHospitalForm.outDate!=null) {
				$('#money_description').hide();
				$('#pledge_description').show();
			}else {
				$('#money_description').show();
				$('#pledge_description').hide();
			}
			
			if(response.data[0].elderBeHospitalForm.beStatus==2) {
				$('#btnCostSettlementOK').hide();
			}else {
				$('#btnCostSettlementOK').show();
			}
		}
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return getSubsidizationValue(subsidization, subsidizationValue);
				},
				getSubsidizationUnit:function(subsidization) {
					return getSubsidizationUnit(subsidization);
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return getSubsidizationText(subsidization, subsidizationValue);
				},
				getConsDeductionText:function(consumptionWay, consDeductionWay) {
					return getConsDeductionText(consumptionWay, consDeductionWay);
				},
				//总共可扣月数
				getTotalMonths:function(todo) {
					return getTotalMonths(todo);
				},
				//剩余可扣月数
				getRemainMonths:function(todo) {
					return getRemainMonths(todo);
				},
				//已扣月数
				getAlreadyUsedMonths:function(todo) {
					return getAlreadyUsedMonths(todo);
				},
				//总共可扣天数
				getTotalNumber:function(todo) {
					return getTotalNumber(todo);
				},
				//剩余可扣天数
				getRemainNumber:function(todo) {
					return getRemainNumber(todo);
				},
				//已扣天数
				getAlreadyUsedNumber:function(todo) {
					return getAlreadyUsedNumber(todo);
				},
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				}
			}
		});
		
		view.data.elderId = response.data[0].elder.elderId;
		view.data.elderName = response.data[0].elder.name;
		view.data.sex = response.data[0].elder.sex;
		view.data.birthday = response.data[0].elder.birthday;
		view.data.peoples = response.data[0].elder.peoples;
		view.data.cardId = response.data[0].elder.cardId;
		view.data.maritalStatus = response.data[0].elder.maritalStatus;
		view.data.registeredResidence = response.data[0].elder.registeredResidence;
		view.data.liveAddress = response.data[0].elder.liveAddress;
		if(response.data[0].subjectRoom) {
			view.data.subjectRoomName = response.data[0].subjectRoom.roomName;
		}
		if(response.data[0].building) {
			view.data.buildingName = response.data[0].building.buildingName;
			view.data.floorName = response.data[0].floor.floorName;
			view.data.roomName = response.data[0].room.roomName;
			view.data.roomType = response.data[0].room.roomType;
			view.data.bedNumber = response.data[0].bed.bedNumber;
		}
		if(response.data[0].nursingCost) {
			view.data.nursingDesc = response.data[0].nursingCost.nursingCostName;
		}
		if(response.data[0].baseServiceCost) {
			view.data.baseServiceDesc = response.data[0].baseServiceCost.serviceName;
		}
		
		if(response.data[0].elderBeHospitalForm == null) {
			alert('该长者未办理入院登记');
			return;
		}
		view.data.elderBeHospitalId = response.data[0].elderBeHospitalForm.beHospitalId;
		//view.data.userVipCardForm = response.data[0].userVipCardForm;
		//view.data.elderBeHospitalForm = response.data[0].elderBeHospitalForm;
		
		if(response.data[0].nursingCost) {
			view.data.nursingCostForHalfMoon = (response.data[0].nursingCost.price/2).toFixed(2);
			$('#nursingCostForHalfMoon').text(view.data.nursingCostForHalfMoon+'元（半个月）');
		}
		
		/*
		view.data.baseServiceCostForHalfMoon = (response.data[0].baseServiceCost.price/2).toFixed(2);
		$('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（半个月）');
		*/
		
		if(response.data[0].baseServiceCost) {
			if(response.data[0].baseServiceCost.deductionWay=='半个月扣费') {
				view.data.baseServiceCostForHalfMoon = (response.data[0].baseServiceCost.price/2).toFixed(2);
				$('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（半个月）');
			}else {
				view.data.baseServiceCostForHalfMoon = response.data[0].baseServiceCost.price;
				$('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（一个月）');
			}
		}
		
		if(response.data[0].elderBeHospitalForm) {
			elderBeHospital = response.data[0].elderBeHospitalForm;
			
			view.data.houseTypeType = response.data[0].elderBeHospitalForm.houseTypeType;
			
			if(view.data.houseTypeType==1) {
				$('#houseTypeType').text('来源：VIP卡');
				if(response.data[0].userVipCardForm.consumptionWay=='半个月扣费') {
					view.data.bedCostForHalfMoon = response.data[0].userVipCardForm.pricePerDay*15;
					$('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（半个月）');
				}else {
					view.data.bedCostForHalfMoon = response.data[0].userVipCardForm.pricePerDay*30;
					$('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（一个月）');
				}
			}else {
				view.data.bedCostForHalfMoon = (response.data[0].elderBeHospitalForm.bedCostPrice/2).toFixed(2);
				$('#houseTypeType').text('来源：现金');
				$('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（半个月）');
			}
		}
		
		
		$('#vue_vm_list').show();
		$('#vue_vm_list div').show();
		
		if(load_foodAllowance_select) {
			load_foodAllowance_select();
		}
		if(elderOutCost_findElderOutCost) {
			elderOutCost_findElderOutCost(view.data.elderId);
		}
	});
}

findElderInfoByType = function(elderType) {
    if($('#vue_vm_list').length==0) {return;}
    $('#vue_vm_list div').hide();

	var searchVal = $.url().param('elderCardId');
	if(isEmpty(searchVal)) {
		searchVal = $('#searchVal').val();
		if(isEmpty(searchVal)) {
			searchVal = $.url().param('searchVal');
		}
	}

    if(isEmpty(searchVal)) {
        alert('请输入长者姓名或身份证号');
        return;
    }
    beHospitalId = $.url().param('beHospitalId');

    find_basic_by_json(path+'/beHospitalFees/findElderInfoByType',
        {searchVal:searchVal, elderType:elderType,beHospitalId:beHospitalId}, function(response) {
        $('#vue_vm_list').html(gl_vue_vm_list_html);

        if(response.data.length > 0) {
            var pledgePay = response.data[0].beHospitalFeeForm==null? 0: response.data[0].beHospitalFeeForm.pledgePay;
            $('#pledgePay').text(pledgePay+'元');
            $('#pledgePay_input').val(pledgePay);
        }

        if(response.data[0].elderBeHospitalForm!=null) {
            if(response.data[0].elderBeHospitalForm.outDate!=null) {
                $('#money_description').hide();
                $('#pledge_description').show();
            }else {
                $('#money_description').show();
                $('#pledge_description').hide();
            }

            // if(response.data[0].elderBeHospitalForm.beStatus==2) {
            //     $('#btnCostSettlementOK').hide();
            // }else {
            //     $('#btnCostSettlementOK').show();
            // }
        }
        var subjectRoomManager = $.url().param('subjectRoomManager');
        var createTime = $.url().param('createTime');
        new Vue({
            el: '#vue_vm_list',
            data: {
                todos: response.data,
                subjectRoomManager:subjectRoomManager,
                createTime:createTime
            },
            methods: {
                getSubsidizationValue:function(subsidization, subsidizationValue) {
                    return getSubsidizationValue(subsidization, subsidizationValue);
                },
                getSubsidizationUnit:function(subsidization) {
                    return getSubsidizationUnit(subsidization);
                },
                getSubsidizationText:function(subsidization, subsidizationValue) {
                    return getSubsidizationText(subsidization, subsidizationValue);
                },
                getConsDeductionText:function(consumptionWay, consDeductionWay) {
                    return getConsDeductionText(consumptionWay, consDeductionWay);
                },
                //总共可扣月数
                getTotalMonths:function(todo) {
                    return getTotalMonths(todo);
                },
                //剩余可扣月数
                getRemainMonths:function(todo) {
                    return getRemainMonths(todo);
                },
                //已扣月数
                getAlreadyUsedMonths:function(todo) {
                    return getAlreadyUsedMonths(todo);
                },
                //总共可扣天数
                getTotalNumber:function(todo) {
                    return getTotalNumber(todo);
                },
                //剩余可扣天数
                getRemainNumber:function(todo) {
                    return getRemainNumber(todo);
                },
                //已扣天数
                getAlreadyUsedNumber:function(todo) {
                    return getAlreadyUsedNumber(todo);
                },
                getChepingUrl:function(elderId, elderName, elderCardId) {
                    return getChepingUrl(elderId, elderName, elderCardId);
                }
            }
        });

        view.data.elderId = response.data[0].elder.elderId;
        view.data.elderName = response.data[0].elder.name;
        view.data.sex = response.data[0].elder.sex;
        view.data.birthday = response.data[0].elder.birthday;
        view.data.peoples = response.data[0].elder.peoples;
        view.data.cardId = response.data[0].elder.cardId;
        view.data.maritalStatus = response.data[0].elder.maritalStatus;
        view.data.registeredResidence = response.data[0].elder.registeredResidence;
        view.data.liveAddress = response.data[0].elder.liveAddress;
        if(response.data[0].subjectRoom) {
            view.data.subjectRoomName = response.data[0].subjectRoom.roomName;
        }
        if(response.data[0].building) {
            view.data.buildingName = response.data[0].building.buildingName;
            view.data.floorName = response.data[0].floor.floorName;
            view.data.roomName = response.data[0].room.roomName;
            view.data.roomType = response.data[0].room.roomType;
            view.data.bedNumber = response.data[0].bed.bedNumber;
        }
        if(response.data[0].nursingCost) {
            view.data.nursingDesc = response.data[0].nursingCost.nursingCostName;
        }
        if(response.data[0].baseServiceCost) {
            view.data.baseServiceDesc = response.data[0].baseServiceCost.serviceName;
        }

        if(response.data[0].elderBeHospitalForm == null) {
            alert('该长者未办理入院登记');
            return;
        }
        view.data.elderBeHospitalId = response.data[0].elderBeHospitalForm.beHospitalId;
        //view.data.userVipCardForm = response.data[0].userVipCardForm;
        //view.data.elderBeHospitalForm = response.data[0].elderBeHospitalForm;

        if(response.data[0].nursingCost) {
            view.data.nursingCostForHalfMoon = (response.data[0].nursingCost.price/2).toFixed(2);
            $('#nursingCostForHalfMoon').text(view.data.nursingCostForHalfMoon+'元（半个月）');
        }

        /*
        view.data.baseServiceCostForHalfMoon = (response.data[0].baseServiceCost.price/2).toFixed(2);
        $('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（半个月）');
        */

        if(response.data[0].baseServiceCost) {
            if(response.data[0].baseServiceCost.deductionWay=='半个月扣费') {
                view.data.baseServiceCostForHalfMoon = (response.data[0].baseServiceCost.price/2).toFixed(2);
                $('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（半个月）');
            }else {
                view.data.baseServiceCostForHalfMoon = response.data[0].baseServiceCost.price;
                $('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（一个月）');
            }
        }

        if(response.data[0].elderBeHospitalForm) {
            elderBeHospital = response.data[0].elderBeHospitalForm;

            view.data.houseTypeType = response.data[0].elderBeHospitalForm.houseTypeType;

            if(view.data.houseTypeType==1) {
                $('#houseTypeType').text('来源：VIP卡');
                if(response.data[0].userVipCardForm.consumptionWay=='半个月扣费') {
                    view.data.bedCostForHalfMoon = response.data[0].userVipCardForm.pricePerDay*15;
                    $('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（半个月）');
                }else {
                    view.data.bedCostForHalfMoon = response.data[0].userVipCardForm.pricePerDay*30;
                    $('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（一个月）');
                }
            }else {
                view.data.bedCostForHalfMoon = (response.data[0].elderBeHospitalForm.bedCostPrice/2).toFixed(2);
                $('#houseTypeType').text('来源：现金');
                $('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（半个月）');
            }
        }


        $('#vue_vm_list div').show();

        if(load_foodAllowance_select) {
            load_foodAllowance_select();
        }
        if(elderOutCost_findElderOutCost) {
            elderOutCost_findElderOutCost(elderBeHospital.beHospitalId);
        }
    });
}

findElder = function(elderCardId) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	
	var searchVal = elderCardId;
	if(isEmpty(searchVal)) {
		searchVal = $('#searchVal').val();
		if(isEmpty(searchVal)) {
			searchVal = $.url().param('searchVal');
		}
	}
	
	if(isEmpty(searchVal)) {
		alert('请输入长者姓名或身份证号');
		return;
	}
	
	find_basic(path+'/beHospitalFees/findElderInfo', searchVal, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		if(response.data.length > 0) {
			var pledgePay = response.data[0].beHospitalFeeForm==null? 0: response.data[0].beHospitalFeeForm.pledgePay;
			$('#pledgePay').text(pledgePay+'元');
			$('#pledgePay_input').val(pledgePay);
		}
		
		if(response.data[0].elderBeHospitalForm!=null) {
			if(response.data[0].elderBeHospitalForm.outDate!=null) {
				$('#money_description').hide();
				$('#pledge_description').show();
			}else {
				$('#money_description').show();
				$('#pledge_description').hide();
			}
			
			if(response.data[0].elderBeHospitalForm.beStatus==2) {
				$('#btnCostSettlementOK').hide();
			}else {
				$('#btnCostSettlementOK').show();
			}
		}
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return getSubsidizationValue(subsidization, subsidizationValue);
				},
				getSubsidizationUnit:function(subsidization) {
					return getSubsidizationUnit(subsidization);
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return getSubsidizationText(subsidization, subsidizationValue);
				},
				getConsDeductionText:function(consumptionWay, consDeductionWay) {
					return getConsDeductionText(consumptionWay, consDeductionWay);
				},
				//总共可扣月数
				getTotalMonths:function(todo) {
					return getTotalMonths(todo);
				},
				//剩余可扣月数
				getRemainMonths:function(todo) {
					return getRemainMonths(todo);
				},
				//已扣月数
				getAlreadyUsedMonths:function(todo) {
					return getAlreadyUsedMonths(todo);
				},
				//总共可扣天数
				getTotalNumber:function(todo) {
					return getTotalNumber(todo);
				},
				//剩余可扣天数
				getRemainNumber:function(todo) {
					return getRemainNumber(todo);
				},
				//已扣天数
				getAlreadyUsedNumber:function(todo) {
					return getAlreadyUsedNumber(todo);
				},
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				}
			}
		});
		
		view.data.elderId = response.data[0].elder.elderId;
		view.data.elderName = response.data[0].elder.name;
		view.data.sex = response.data[0].elder.sex;
		view.data.birthday = response.data[0].elder.birthday;
		view.data.peoples = response.data[0].elder.peoples;
		view.data.cardId = response.data[0].elder.cardId;
		view.data.maritalStatus = response.data[0].elder.maritalStatus;
		view.data.registeredResidence = response.data[0].elder.registeredResidence;
		view.data.liveAddress = response.data[0].elder.liveAddress;
		if(response.data[0].subjectRoom) {
			view.data.subjectRoomName = response.data[0].subjectRoom.roomName;
		}
		if(response.data[0].building) {
			view.data.buildingName = response.data[0].building.buildingName;
			view.data.floorName = response.data[0].floor.floorName;
			view.data.roomName = response.data[0].room.roomName;
			view.data.roomType = response.data[0].room.roomType;
			view.data.bedNumber = response.data[0].bed.bedNumber;
		}
		if(response.data[0].nursingCost) {
			view.data.nursingDesc = response.data[0].nursingCost.nursingCostName;
		}
		if(response.data[0].baseServiceCost) {
			view.data.baseServiceDesc = response.data[0].baseServiceCost.serviceName;
		}
		
		if(response.data[0].elderBeHospitalForm == null) {
			alert('该长者未办理入院登记');
			return;
		}
		view.data.elderBeHospitalId = response.data[0].elderBeHospitalForm.beHospitalId;
		//view.data.userVipCardForm = response.data[0].userVipCardForm;
		//view.data.elderBeHospitalForm = response.data[0].elderBeHospitalForm;
		
		if(response.data[0].nursingCost) {
			view.data.nursingCostForHalfMoon = (response.data[0].nursingCost.price/2).toFixed(2);
			$('#nursingCostForHalfMoon').text(view.data.nursingCostForHalfMoon+'元（半个月）');
		}
		
		/*
		view.data.baseServiceCostForHalfMoon = (response.data[0].baseServiceCost.price/2).toFixed(2);
		$('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（半个月）');
		*/
		
		if(response.data[0].baseServiceCost) {
			if(response.data[0].baseServiceCost.deductionWay=='半个月扣费') {
				view.data.baseServiceCostForHalfMoon = (response.data[0].baseServiceCost.price/2).toFixed(2);
				$('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（半个月）');
			}else {
				view.data.baseServiceCostForHalfMoon = response.data[0].baseServiceCost.price;
				$('#baseServiceCostForHalfMoon').text(view.data.baseServiceCostForHalfMoon+'元（一个月）');
			}
		}
		
		if(response.data[0].elderBeHospitalForm) {
			elderBeHospital = response.data[0].elderBeHospitalForm;
			
			view.data.houseTypeType = response.data[0].elderBeHospitalForm.houseTypeType;
			
			if(view.data.houseTypeType==1) {
				$('#houseTypeType').text('来源：VIP卡');
				if(response.data[0].userVipCardForm.consumptionWay=='半个月扣费') {
					view.data.bedCostForHalfMoon = response.data[0].userVipCardForm.pricePerDay*15;
					$('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（半个月）');
				}else {
					view.data.bedCostForHalfMoon = response.data[0].userVipCardForm.pricePerDay*30;
					$('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（一个月）');
				}
			}else {
				view.data.bedCostForHalfMoon = (response.data[0].elderBeHospitalForm.bedCostPrice/2).toFixed(2);
				$('#houseTypeType').text('来源：现金');
				$('#bedCostForHalfMoon').text(view.data.bedCostForHalfMoon+'元（半个月）');
			}
		}
		
		
		$('#vue_vm_list div').show();
		
		if(load_foodAllowance_select) {
			load_foodAllowance_select();
		}
		if(elderOutCost_findElderOutCost) {
			elderOutCost_findElderOutCost(elderBeHospital.beHospitalId);
		}
	});
}

function addBeTime() {
	var elder_add_month = {};
	elder_add_month.elderId = $('#elderId').val();
	elder_add_month.monthNum = parseInt($('#monthNum').val());

	save_basic(path+'/beHospitalFees/addBeTime', elder_add_month, function() {
		alert('住院时长增加成功');
	});
}

function beHospitalFeesFind() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	var searchVal = $('#searchVal').val();

	find_basic_by_json(path+'/beHospitalFees/find', {searchVal: searchVal}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		for(var i=0; i<response.data.length; i++) {
			var outHospitalTime = new Date(response.data[i].outHospitalTime).getTime();
			var beHospitalTime = new Date(response.data[i].beHospitalTime).getTime();
			var remainDayNum = Math.floor((outHospitalTime-beHospitalTime)/(24*3600*1000));
			response.data[i].remainDayNum = remainDayNum? remainDayNum: 0;
		}
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/beHospitalFees/deleteBatch');
}

function feesInputChange() {
	var variablePay = parseFloat($('#pledgePay').val()) + parseFloat($('#mealCardPay').val()) + parseFloat($('#elderWalletPay').val())
				+ parseFloat($('#electricityPay').val()) + parseFloat($('#waterPay').val()) + parseFloat($('#hotWaterPay').val());
				
	view.data.totalPay = variablePay
				/*
				+ parseFloat(view.data.nursingCostForHalfMoon)
				+ parseFloat(view.data.baseServiceCostForHalfMoon)
				+ parseFloat(view.data.bedCostForHalfMoon)
				*/
				;
				
	view.data.realityPay = parseFloat($('#pledgePay').val()) + parseFloat($('#elderWalletPay').val());
	
	$('#realityPay').text(view.data.realityPay+'元');
	$('#totalPay').text(view.data.totalPay+'元');
}

var returnMoney;
elderOutCost_findElderOutCost = function(beHospitalId) {
	if($('#vue_vm_list_elderOutCost').length==0) {return;}
	$('#vue_vm_list_elderOutCost div').hide();

		find_basic_by_json(path+'/elderOutCost/findElderOutCost', {beHospitalId: beHospitalId}, function(response) {
		$('#vue_vm_list_elderOutCost').html(gl_vue_vm_list_elderOutCost_html);
		
		new Vue({
			el: '#vue_vm_list_elderOutCost',
			data: {
				todos: response.data
			},
			methods: {
				getBalanceTotal:function(todo) {
					var pledgePay = 0;
					if($('#pledgePay_input').length > 0) {
						var pledgePay_input = $('#pledgePay_input').val();
						pledgePay = (pledgePay_input==''? 0: parseFloat(pledgePay_input));
					}
					
					var walletBalance = (todo.walletBalance==null? 0: todo.walletBalance);
					var mealCardBalance = (todo.mealCardBalance==null? 0: todo.mealCardBalance);
					
					return (pledgePay+walletBalance+mealCardBalance).toFixed(3);
				},
				//获取欠费合计
				getArrearageDescFormsTotal:function(arrearageDescForms) {
					var totalMoney = 0;
					for(var i=0; i<arrearageDescForms.length; i++) {
						var price = arrearageDescForms[i].price;
						var quantity = arrearageDescForms[i].arrearageQuantity;
						totalMoney += parseFloat((price*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
					}
					
					return totalMoney;
				},
				//获取赔偿金合计
				getElderCompDescFormsTotal:function(elderCompDescForms) {
					var totalMoney = 0;
					for(var i=0; i<elderCompDescForms.length; i++) {
						var price = elderCompDescForms[i].price;
						var quantity = elderCompDescForms[i].compQuantity;
						totalMoney += parseFloat((price*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
					}
                    returnMoney = totalMoney;
					return totalMoney;
				},
				getRemainTotal:function(todo) {
					return this.getBalanceTotal(todo)
						- this.getArrearageDescFormsTotal(todo.arrearageDescForms)
						- this.getElderCompDescFormsTotal(todo.elderCompDescForms);
				},
				getRemainTotalText:function(todo) {
					var remainTotal = this.getRemainTotal(todo);
					var remainTotalText;
					
					if(remainTotal==0) {
						remainTotalText = remainTotal+' 元（无需退费，也无需补交）';
					}else if(remainTotal>0) {
						remainTotalText = '退 '+remainTotal+' 元';
					}else {
						remainTotalText = '补交 '+remainTotal+' 元';
					}
					
					return remainTotalText;
				}
			}
		});
		
		$('#vue_vm_list_elderOutCost div').show();
	});
}

function elderOutCost_costSettlement() {

	save_basic_by_json(path+'/elderOutCost/costSettlement', {beHospitalId:beHospitalId}, function() {
		alert('提交成功');
        goNextPage02(returnMoney);
		/*window.open('3-4-3cyjieqing-1.html?elderCardId='+view.data.cardId);*/
		// window.open('3-7-7paylist.html?elderCardId='+view.data.cardId);
	});
}

function openFloorPage() {
	window.open('3-6-2lrcha-by-floor.html');
}